﻿#include "loading.h"
#include "gamepanel.h"
#include <QPainter>
#include <QTimer>

Loading::Loading(QWidget *parent) : QWidget(parent)
{
    m_dist=0;
    m_bk.load(":/images/loading.png");
    setFixedSize(m_bk.width(),m_bk.height());
    //去边框
    setWindowFlags(Qt::FramelessWindowHint | windowFlags());
    //背景透明
    setAttribute(Qt::WA_TranslucentBackground);

    QPixmap pixmap(":/images/progress.png");
    QTimer* timer=new QTimer(this);
    connect(timer,&QTimer::timeout,this,[=](){
        m_progress=pixmap.copy(0,0,m_dist,pixmap.height());
        m_dist+=5;
        update();
        if(m_dist>pixmap.width()+10)
        {
            timer->stop();
            timer->deleteLater();
            GamePanel* panel=new GamePanel;
            panel->show();
            close();
        }
    });
    timer->start(15);
}

void Loading::paintEvent(QPaintEvent *ev)
{
    Q_UNUSED(ev);
    QPainter painter(this);
    painter.drawPixmap(rect(),m_bk);
    painter.drawPixmap(62,417,m_progress.width(),m_progress.height(),m_progress);

}
